---
title: useFocusEffect
---

Similar to React `useEffect`, but only runs when the current route is focused. This is directly based off [React Navigation's useFocusEffect](https://reactnavigation.org/docs/use-focus-effect/).

You must pass it an array as the second argument to determine memoization, otherwise the effect will not change.

Example:

```tsx
import { useFocusEffect } from '@react-navigation/native'
import { useCallback } from 'react'

function Profile({ userId }) {
  const [user, setUser] = React.useState(null)

  useFocusEffect(
    () => {
      const unsubscribe = API.subscribe(userId, (user) => setUser(user))
      return () => unsubscribe()
    },
    [userId]
  )

  return <ProfileContent user={user} />
}
```
